package com.algo.pattern.command.command;

/**
 * 美团请求命令工厂类
 */
public class MeituanRequestCommandFactory {

    /**
     * 根据命令类型获取美团请求命令
     * @param commandType
     * @return
     */
    public static MeituanRequestCommand create(CommandType commandType) {
        Class<?> clazz = commandType.getClazz();
        MeituanRequestCommand command = null;
        try {
            command = (MeituanRequestCommand) clazz.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return command;
    }

    /**
     * 命令类型
     */
    public enum CommandType {
        CANCEL_ORDER(CancelOrderRequestCommand.class, "取消美团订单命令类型"),
        QUERY_ORDER(QueryOrderRequestCommand.class, "查询美团订单命令类型");

        private Class<? extends AbstractMeituanRequestCommand> clazz;
        private String desc;

        CommandType(Class<? extends AbstractMeituanRequestCommand> clazz, String desc) {
            this.clazz = clazz;
            this.desc = desc;
        }

        public Class<? extends AbstractMeituanRequestCommand> getClazz() {
            return clazz;
        }
    }

}
